package testing;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;

public class TestStructures
{
	public static void main(String[] args)
	{
		try {
			Charset charser = Charset.forName("UTF-8");
			CharsetEncoder encode = charser.newEncoder();
			BufferedReader dsa = new BufferedReader(new FileReader("3arabi.txt"));
			String t = dsa.readLine();
			ByteBuffer buff = encode.encode(CharBuffer.wrap(t));
			@SuppressWarnings("unused")
			byte[] b = buff.array();
			FileOutputStream outStream = new FileOutputStream("lolo.txt");
			FileChannel out = outStream.getChannel();
			out.write(buff);
			out.close();
			outStream.close();
			BufferedInputStream in = new BufferedInputStream(new FileInputStream("lolo.txt"));
			byte[] buffOut = new byte[10];
			in.read(buffOut);
			CharsetDecoder decoder = charser.newDecoder();
			CharBuffer charBuff = decoder.decode(ByteBuffer.wrap(buffOut));
			String s = charBuff.toString();
			System.out.println(s);
			PrintWriter printer = new PrintWriter(new FileWriter("outiii.txt"));
			printer.println(s);
			printer.close();
			in.close();
		} catch (CharacterCodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}

}
